package com.jcrj.dao.imp;

import java.io.Serializable;
import java.sql.SQLException;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.jcrj.dao.WorkflowManagerDao;
import com.jcrj.entity.OAuthority;
import com.jcrj.entity.OFlowType;
import com.jcrj.entity.OFormColumn;
import com.jcrj.entity.ONode;
import com.jcrj.entity.ONodeTransaction;
import com.jcrj.entity.OProcessHis;
import com.jcrj.entity.OProcessinstance;
import com.jcrj.entity.OTaskActor;
import com.jcrj.entity.OWorkflow;

public class WorkflowManagerImp extends AbstractBaseDaoImp implements WorkflowManagerDao {
	public void saveWorkflow(OWorkflow workflow) {
		getHibernateTemplate().save(workflow);
	}

	public void updateWorkflow(OWorkflow workflow) {
		getHibernateTemplate().update(workflow);
	}

	public void deleteWorkflow(OWorkflow workflow) {
		getHibernateTemplate().delete(workflow);
	}

	public void deleteFlowType(OFlowType flowtype) {
		getHibernateTemplate().delete(flowtype);
	}

	public void saveFlowType(OFlowType flowtype) {
		getHibernateTemplate().save(flowtype);
	}

	public void updateFlowType(OFlowType flowtype) {
		getHibernateTemplate().update(flowtype);
	}

	public void saveAuthority(OAuthority authority) {
		getHibernateTemplate().save(authority);
	}

	public Serializable saveFlowNode(ONode node) {
		return getHibernateTemplate().save(node);
	}

	public void saveNodeTransition(ONodeTransaction nodeTransaction) {
		getHibernateTemplate().save(nodeTransaction);
	}

	public void updateFlowNode(ONode node) {
		getHibernateTemplate().update(node);
	}

	public void deleteNodeTransition(ONodeTransaction nodeTransaction) {
		getHibernateTemplate().delete(nodeTransaction);
	}

	public void updateNodeTransition(ONodeTransaction nodeTransaction) {
		getHibernateTemplate().update(nodeTransaction);
	}

	public void deleteTaskActor(OTaskActor taskActor) {
		getHibernateTemplate().delete(taskActor);
	}

	public void saveTaskActor(OTaskActor taskActor) {
		getHibernateTemplate().save(taskActor);
	}

	public void updateTaskActor(OTaskActor taskActor) {
		getHibernateTemplate().update(taskActor);
	}

	public ONode getStartNode(final String hql) {
		return (ONode) getHibernateTemplate().execute(new HibernateCallback() {
			public Object doInHibernate(Session session) throws HibernateException, SQLException {
				Query query = session.createQuery(hql);
				return query.uniqueResult();
			}
		});
	}

	public void saveOProcessinstance(OProcessinstance processinstance) {
		getHibernateTemplate().save(processinstance);
	}

	public void updateOProcessinstance(OProcessinstance processinstance) {
		getHibernateTemplate().update(processinstance);
	}

	public void deleteProcessHis(OProcessHis processHistory) {
		getHibernateTemplate().delete(processHistory);
	}

	public void saveProcessHis(OProcessHis processHistory) {
		getHibernateTemplate().save(processHistory);
	}

	public void updateProcessHis(OProcessHis processHistory) {
		getHibernateTemplate().update(processHistory);
	}

	public void saveFormColumn(OFormColumn column) {
		getHibernateTemplate().save(column);
	}

	public void updateFormColumn(OFormColumn column) {
		getHibernateTemplate().update(column);
	}
 }